<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('电子名片新闻列列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <input name="channelId" id="channelId" type="hidden">
                <div class="select-list">
                    <ul>
                       <!-- <li>
                            <label>机构：</label>
                            <select name="deptId" id="deptId" onchange="deptChange()"
                                    th:with="type=${@dept.selectDeptListByType('2')}">
                                <option value="">所有</option>
                                <option th:each="dept : ${type}" th:text="${dept.deptName}"
                                        th:value="${dept.deptId}"></option>
                            </select>
                        </li>-->
                        <li>
                            <label>频道：</label>
                            <select name="channelIds" id="channelIds" onchange="channelIdChange()">
                                <option value="">所有</option>
                            </select>
                        </li>
                        <li>
                            <label>来源：</label>
                            <input type="text" name="source"/>
                        </li>
                        <li>
                        <li>
                            <label>发布时间：</label>
                            <input type="text" class="time-input" placeholder="请选择发布时间"
                                   name="pubDate"/>
                        </li>
                        <li>
                            <label>首页显示：</label>
                            <select name="indexSts"
                                    th:with="type=${@dict.getType('common_yes_no')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>热点新闻：</label>
                            <select name="hotSts"
                                    th:with="type=${@dict.getType('common_yes_no')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>状态：</label>
                            <select name="sts"
                                    th:with="type=${@dict.getType('sys_sts')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="config:contentList:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="config:contentList:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="config:contentList:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <!--<a class="btn btn-success" onclick="downLoad()" shiro:hasPermission="config:contentList:downLoad">
                <i class="fa fa-download"></i> 下载
            </a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('config:contentList:edit')}]];
    var removeFlag = [[${@permission.hasPermi('config:contentList:remove')}]];
    var deptIdDatas = [[${@dept.selectDeptListByType('2')}]];
    var prefix = ctx + "config/contentList";

    $(function () {
        deptChange();
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "新闻",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: 'ID',
                    visible: false
                },
                {
                    field: 'title',
                    title: '标题'
                },
                {
                    field: 'img',
                    title: '标题图片',
                    formatter: function (value, row, index) {
                        return $.table.imageView(row.img, 274, 650);
                    }
                },
                {
                    field: 'name',
                    title: '频道'
                },
                {
                    field: 'source',
                    title: '来源'
                },
                {
                    field: 'pubDate',
                    title: '发布时间'
                },
                {
                    visible: editFlag == 'hidden' ? false : true,
                    title: '首页显示',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return indexStsTools(row);
                    }
                },
                {
                    visible: editFlag == 'hidden' ? false : true,
                    title: '热点新闻',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return hotStsTools(row);
                    }
                },
                {
                    visible: editFlag == 'hidden' ? false : true,
                    title: '状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                }/*,
                {
                    field: 'deptId',
                    title: '法人机构',
                    formatter: function (value, row, index) {
                        return selectDeptName(deptIdDatas, value);
                    }
                }*/,
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function downLoad() {
        var url = prefix + "/down";
        $.modal.open('下载新闻', url, 500, 500);

    }

    function selectDeptName(deptIdDatas, value) {
        if ($.common.isEmpty(deptIdDatas) || $.common.isEmpty(value)) {
            return '';
        }
        var actions = [];
        $.each(deptIdDatas, function (index, dept) {
            if (dept.deptId == ('' + value)) {
                var listClass = $.common.equals("default", dept.listClass) || $.common.isEmpty(dept.listClass) ? "" : "badge badge-" + dept.listClass;
                actions.push($.common.sprintf("<span class='%s'>%s</span>", listClass, dept.deptName));
                return false;
            }
        });
        return actions.join('');
    }

    function deptChange() {
        var deptId = $('#deptId').val();
        if (deptId != "") {
            $.ajax({
                type: "post",
                url: ctx + "config/channelList/channelList",
                data: {"deptId": deptId},
                success: function (result) {
                    if (result.code == web_status.SUCCESS) {
                        var channelIdStr = '<option value="">所有</option>';
                        var channelData = result.data;
                        for (var i = 0; i < channelData.length; i++) {
                            channelIdStr += '<option value="' + channelData[i].channelId + '">' + channelData[i].name + '</option>';
                        }
                        $('#channelIds').html(channelIdStr);
                    }
                }
            });
        }
    }

    function channelIdChange() {
        $('#channelId').val($('#channelIds').val());
    }

    function reset() {
        $('#channelId').val("");
        $.form.reset();
    }
    /* 状态显示 */
    function statusTools(row) {
        if (row.sts == 0) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
        }
    }

    /* 状态停用 */
    function disable(id) {
        $.modal.confirm("确认要停用新闻吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"id": id, "sts": 0});
        })
    }

    /* 状态启用 */
    function enable(id) {
        $.modal.confirm("确认要启用新闻吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"id": id, "sts": 1});
        })
    }

    /* 状态显示 */
    function statusTools(row) {
        if (row.sts == 0) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
        }
    }

    /* 状态停用 */
    function disable(id) {
        $.modal.confirm("确认要停用新闻吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"id": id, "sts": 0});
        })
    }

    /* 状态启用 */
    function enable(id) {
        $.modal.confirm("确认要启用新闻吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"id": id, "sts": 1});
        })
    }

    /* 首页显示状态显示 */
    function indexStsTools(row) {
        if (row.indexSts == "F") {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="indexStsEnable(\'' + row.id + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="indexStsDisable(\'' + row.id + '\')"></i> ';
        }
    }

    /* 首页显示启用 */
    function indexStsEnable(id) {
        $.modal.confirm("确认要启用首页显示吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"id": id, "indexSts": "T"});
        })
    }

    /* 首页显示停用 */
    function indexStsDisable(id) {
        $.modal.confirm("确认要停用首页显示吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"id": id, "indexSts": "F"});
        })
    }

    /* 热点新闻状态显示 */
    function hotStsTools(row) {
        if (row.hotSts == "F") {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="hotStsEnable(\'' + row.id + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="hotStsDisable(\'' + row.id + '\')"></i> ';
        }
    }

    /* 热点新闻启用 */
    function hotStsEnable(id) {
        $.modal.confirm("确认要设为热点新闻吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"id": id, "hotSts": "T"});
        })
    }

    /* 热点新闻停用 */
    function hotStsDisable(id) {
        $.modal.confirm("确认要取消热点新闻吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"id": id, "hotSts": "F"});
        })
    }
</script>
</body>
</html>